import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/socket/type_model.dart';
import 'package:animal/ui/friend/controller/friend_info_controller.dart';
import 'package:animal/ui/friend/model/friend_model.dart';
import 'package:animal/ui/friend/model/search_user_model.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/HeaderWidget.dart';
import 'package:animal/widgets/appbar_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

///好友详情
class FriendInfoPage extends StatelessWidget {
  final UserModel userModel;

  FriendInfoPage({Key? key,required this.userModel}) : super(key: key);
  final FriendInfoController controller = Get.put(FriendInfoController());

  @override
  Widget build(BuildContext context) {
    controller.userModel = userModel;
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBarWidget.defaultAppBar(title: const Text("详细资料"), elevation: 1, backgroundColor: Colors.white, actions: [
        PopupMenuButton(
          itemBuilder: (context) => buildItems(),
          offset: const Offset(0, 50),
          color: Colors.white,
          icon: const Icon(Icons.menu),
          elevation: 1,
          shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20),
            bottomRight: Radius.circular(20),
            topRight: Radius.circular(5),
            bottomLeft: Radius.circular(5),
          )),
          onSelected: (e) {
            print(e);
          },
          onCanceled: () => print('onCanceled'),
        )
      ]),
      body: Column(
        children: [
          Stack(
            children: [
              Column(
                children: [
                  Container(
                    color: Colors.blue,
                    height: ScreenUtil().L(100),
                  ),
                  Container(
                    color: Colors.white,
                    height: ScreenUtil().L(100),
                  ),
                ],
              ),
              Column(
                children: [
                  Container(
                    height: ScreenUtil().L(60),
                  ),
                  Header.defaultHead(width: ScreenUtil().L(80), height: ScreenUtil().L(80)),
                  Container(
                    height: ScreenUtil().L(15),
                  ),
                  Visibility(visible: userModel.name != null,
                      child: Text("${userModel.name}", style: KFontConstant.myTextStyle(size: 17, bold: true))),
                  Container(
                    height: ScreenUtil().L(10),
                  ),
                  Text("昵称：${userModel.nickName}",
                          style: KFontConstant.myTextStyle(
                            size: 14,
                          )),
                  Container(
                    height: ScreenUtil().L(10),
                  ),
                  Text("讯号：${userModel.account}",
                          style: KFontConstant.myTextStyle(
                            size: 14,
                          )),
                ],
              )
            ],
          ),
          _item(text: "设置备注", value: userModel.name??""),
          _item(text: "电话号码", value: userModel.phoneNumber),
          _item(text: "描述", value: userModel.riskContext??""),
          _item(text: "来源", value: userModel.addType??""),
          Visibility(
            visible: !userModel.isFriend!,
            child: CupertinoButton(
              child: Text("添加好友", style: KFontConstant.myTextStyle(size: 15, color: Colors.white)),
              onPressed: () => controller.sendFriend(),
              color: Colors.blue,
            ),
          ),
          Container(height: ScreenUtil().L(30)),
          Visibility(
            visible: userModel.isFriend!,
            child: CupertinoButton(
              child: Text("发消息", style: KFontConstant.myTextStyle(size: 15, color: Colors.white)),
              onPressed: () => controller.gotoMessageDetail(),
              color: Colors.blue,
            ),
          ),
        ],
      ),
    );
  }

  Widget _item({String? text, String? value}) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, ScreenUtil().L(18), ScreenUtil().L(15), ScreenUtil().L(18)),
      margin: EdgeInsets.symmetric(horizontal: ScreenUtil().L(20)),
      decoration: BoxDecoration(border: Border(bottom: BorderSide(width: ScreenUtil().L(1), color: KColorConstant.lineE2E5E8))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(text ?? "",
              style: KFontConstant.myTextStyle(
                size: 17,
              )),
          Text(value ?? "",
              style: KFontConstant.myTextStyle(
                size: 17,
              )),
        ],
      ),
    );
  }

  List<PopupMenuItem<String>> buildItems() {
    return controller.map.keys
        .toList()
        .map((e) => PopupMenuItem<String>(
            value: e,
            child: Wrap(
              spacing: 10,
              children: <Widget>[
                Icon(
                  controller.map[e],
                  color: Colors.blue,
                ),
                Text(e),
              ],
            )))
        .toList();
  }
}
